//
//  CircularProgressShape.swift
//  SwiftUIShape
//
//  Created by 李煜 on 2024/8/1.
//

import SwiftUI

struct CircularProgressShape: View {
  private var purpleGradient = LinearGradient(gradient: Gradient(colors: [Color(red: 207 / 255, green: 150 / 255, blue: 207 / 255), Color(red: 107 / 255, green: 116 / 255, blue: 179 / 255)]), startPoint: .trailing, endPoint: .leading)
  
  var body: some View {
    ZStack {
      Circle()
        .stroke(Color(.systemGray6), lineWidth: 20)
        .frame(width: 300, height: 300)
      Circle()
        .trim(from: 0, to: 0.85) // 裁剪0-0.85之间的圆环(.trim只能circle()有这个修饰符,不能和.stroke互换顺序)
        //.fill(.green) //可以试试打开此行,注释上一行
        .stroke(purpleGradient, lineWidth: 20)
        .frame(width: 300, height: 300)
        .overlay {
          VStack {
            Text("85%")
              .font(.system(size: 80, weight: .bold, design: .rounded))
              .foregroundColor(.gray)
            Text("Complete")
              .font(.system(.body, design: .rounded))
              .bold()
              .foregroundColor(.gray)
          }
        }
    }
  }
}

#Preview {
  CircularProgressShape()
}
